package com.xhtt.modules.inspection.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 巡检点
 * </p>
 *
 * @author xj
 * @since 2019-01-18
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class InsPoint extends Model<InsPoint> {

    private static final long serialVersionUID = 1L;

    // 导出使用
    public static final String POINT_TYPE = "*检点类别（设备/检查表）";
    public static final String DEVICE_NAME = "*设备/检查项名称";
    public static final String PID_NUM = "PID位号";
    public static final String DEVICE_TYPE = "设备类别（针对设备：常用/备用）";
    public static final String LABEL_NAME = "*绑定标签";
    public static final String POINT_CONTENT = "*巡检内容";
    public static final String POINT_CONTENT_TYPE = "*巡检内容类别（数值/状态）";
    public static final String VALUE = "标准值";
    public static final String MAX = "最大值";
    public static final String MIN = "最小值";
    public static final String UNIT = "单位";
    public static final String PHOTO = "是否需要拍照";

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 检点名称
     */
    private String name;

    /**
     * 检点状态 1未巡检2已巡检
     */
    private Integer status;

    /**
     * 1.设备2.检查表
     */
    private Integer pointType;

    /**
     * 设备/检查项名称
     */
    private String deviceName;

    /**
     * 1常用2备用
     */
    private Integer deviceType;

    /**
     * 需要巡检？  app 1需要 0不需要
     */
    private Boolean requireFlag;

    @TableLogic
    private int delFlag;

    /**
     * 备注
     */
    private String memo;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    /**
     * 最后一次调整时间
     */
    private LocalDateTime updateTime;

    /**
     * 创建者ID，人工系统创建为0
     */
    private Integer createUserId;

    /**
     * 最后一次调整者ID
     */
    private Integer updateUserId;

    /**
     * 绑定标签名称
     */
    @TableField(exist = false)
    private String labelName;

    /**
     * 绑定标签编码
     */
    @TableField(exist = false)
    private String labelCode;

    @TableField(exist = false)
    private String checkNameStr;

    /**
     * 巡检内容名称
     */
    @TableField(exist = false)
    private List<String> checkNameList;

    /**
     * 巡检内容
     */
    @TableField(exist = false)
    private List<InsPointSubitem> checkList;

    /**
     * 线路排序
     */
    @TableField(exist = false)
    private int sort;

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    public List<String> getCheckNameList() {
        if (StringUtils.isNotEmpty(checkNameStr) && CollectionUtils.isEmpty(checkNameList)) {
            String[] split = checkNameStr.split(",");
            return Arrays.asList(split);
        } else {
            return checkNameList;
        }
    }
}
